package pens.penObjects
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	
	import pens.interfaces.IPenPlayer;
	
	internal class ActionBitmap extends Bitmap implements IPenPlayer
	{
		protected var _isDraw:Boolean=true				
		protected var _canDrow:Boolean=false;
		
		protected var _penDates:Vector.<PenDate>=new Vector.<PenDate>()		
		public function get penDates():Vector.<PenDate>{return _penDates}
		
		protected var _penName:String
		public function get penName():String{return _penName}
		
		public function ActionBitmap(bitmapData:BitmapData=null, pixelSnapping:String="auto", smoothing:Boolean=true)
		{
			super(bitmapData, pixelSnapping, smoothing);
			_penName="基类"
			
			resign()
		}
		
		private var _w:Number=400
		private var _h:Number=300
		
			
		public function draw(w:Number,h:Number):void{
			
		}
			
			
		override public function get height():Number
		{
			// TODO Auto Generated method stub
			return _h;
		}
		
		override public function set height(value:Number):void
		{
			// TODO Auto Generated method stub
			if(_h==value)return;
			_h=value
			resign()
		}
		
		override public function get width():Number
		{
			// TODO Auto Generated method stub
			return _w;
		}
		
		override public function set width(value:Number):void
		{
			// TODO Auto Generated method stub
			if(_w==value)return
			_w=value
			resign()
		}
		
		
		public function resign():void
		{
			_penDates.length=0;			
			if(bitmapData!=null)bitmapData.dispose()	
			bitmapData=new BitmapData(_w,_h,true,0)
		}
		
		public function get isDraw():Boolean
		{
			return _isDraw;;
		}
		
		public function set isDraw(value:Boolean):void
		{
			_isDraw=value
		}
		
		public function moveTo(x:Number, y:Number, size:Number=10, color:uint=0):void
		{
			_canDrow=true
			_penDates.push(new PenDate(_penName,size,color,x,y,PenDate.MOVE_TO))
			_moveTo(x,y,size,color)
		}
		protected function _moveTo(x:Number, y:Number, size:Number=10, color:uint=0):void{}
		
		public function lineTo(x:Number, y:Number, size:Number=10, color:uint=0):void
		{
			if(!_canDrow)return
			_penDates.push(new PenDate(_penName,size,color,x,y,PenDate.LINE_TO))
			_lineTo(x,y,size,color)
		}
		protected function _lineTo(x:Number, y:Number, size:Number=10, color:uint=0):void{}
		
		public function end():void
		{
			_canDrow=false
			_penDates.push(new PenDate(_penName,0,0,0,0,PenDate.END))
			_end()
		}
		protected function _end():void{}
		
		
		
		public function dispose():void
		{
			_penDates.length=0;			
			if(bitmapData!=null)bitmapData.dispose()	
		}
	}
}